<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<form:form id="searchForm" modelAttribute="search" action="index" method="get">
  <div class="section">
    <h2>Search</h2>
    <fieldset>
      <div class="field">
        <div class="label">
          <label for="search">Search String:</label>
        </div>
        <div class="input">
          <form:input id="search" path="search"/>
          <script type="text/javascript">
              Spring.addDecoration(new Spring.ElementDecoration({
                  elementId : "search",
                  widgetType : "dijit.form.ValidationTextBox",
                  widgetAttrs : { promptMessage : "Search expression." }}));
          </script>
        </div>
      </div>

      <div class="field">
        <div class="label">
          <label for="pageSize">Maximum results:</label>
        </div>
        <div class="input">
          <form:select id="pageSize" path="pageSize" cssClass="select">
            <form:options items="${search.pageSizes}"  cssClass="option" />
          </form:select>
          <script type="text/javascript">
            Spring.addDecoration(new Spring.ElementDecoration({
            elementId : "pageSize",
            widgetType : "dijit.form.FilteringSelect",
            widgetAttrs : {
                required: "false"
            }}));
          </script>
        </div>
      </div>

      <div class="buttonGroup">
        <c:if test="${not empty results && page > 0}">
		<a id="prevResultsLink" href="search?search=${search}&pageSize=${pageSize}&page=${page - 1}">&lt;&lt; Previous</a>
		<script type="text/javascript">
		    Spring.addDecoration(new Spring.AjaxEventDecoration({
			elementId: "prevResultsLink",
			event: "onclick",
			params: {fragments: "body"}
		    }));
		</script>
	    </c:if>

        <input type="submit" value="Find" />

        <c:if test="${not empty results && fn:length(results) == pageSize}">
		<a id="moreResultsLink" href="search?search=${search}&pageSize=${pageSize}&page=${page + 1}">Next &gt;&gt;</a>
		<script type="text/javascript">
		    Spring.addDecoration(new Spring.AjaxEventDecoration({
			elementId: "moreResultsLink",
			event: "onclick",
			params: {fragments: "body"}
		    }));
		</script>
	    </c:if>
      </div>
      
    </fieldset>
  </div>
</form:form>